/**
* Copyright (C) 2007 Pedro Miller Rabinovitch.
* http://www.opensource.org/licenses/mit-license.php
*
* Basically, feel free to use it however you want to.
* Please give me credit where appropriate.
*
* Pedro "Shade" Miller, gmail user: pedromr
* http://exodia.org
*
* @author Miller
*
* $Id: RandomWalkBehaviour.as 7 2007-12-13 10:07:21Z pedromr $
*/
package org.exodia.seeds.behaviours {
	import org.exodia.math.Vector3D;
	import org.exodia.seeds.model.Agent;

	/**
	 * Walks around like a small kid in a mega toy store.
	 */
	public class RandomWalkBehaviour implements IBehaviour {
		var _randVecBuffer:Vector3D;
		var _timeForNewThrust:uint;
		var _amount:Number;
		
		public function RandomWalkBehaviour( amount:Number=0.05, timeForNewThrust:uint = 1000 ) {
			_randVecBuffer = Vector3D.create();
			_timeForNewThrust = timeForNewThrust;
			_amount = amount;
		}
		
		public function initialize( agent:Agent ) : void {
			agent.data.nextRandomChange = 0;
			agent.data.currRandThrust = Vector3D.create();
		}
		
		public function tick( agent:Agent, deltaMS:int ) : void {
			//trace( "ticking behaviour "+_randVecBuffer.toString() );
			
			agent.data.nextRandomChange -= deltaMS;
			
			if( agent.data.nextRandomChange <= 0 ) {
				_randVecBuffer.x = 1;
				_randVecBuffer.y = 1;
				_randVecBuffer.length = Math.random() * _amount;
				_randVecBuffer.angle2D = Math.random() * 2 * Math.PI;
				agent.data.currRandThrust.copyFrom( _randVecBuffer );
				
				agent.data.nextRandomChange = _timeForNewThrust;
				
				//trace( "TOTAL X,Y " + [SeparationBehaviour.totalX, SeparationBehaviour.totalY] );
			}
			
			agent.thrust = agent.data.currRandThrust
		}
		
	}
	
}
